#ifndef __XORCRYPTO_H__
#define __XORCRYPTO_H__

namespace encrypted
{
    namespace tunnel
	{

        template<typename KeyBuffType>
        class XORCrypto
        {
        public:
            XORCrypto(KeyBuffType key, size_t keysize)
                : key(key), keysize(keysize), keyindex(0)
            {
            }
            ~XORCrypto()
            {
            }
            size_t cryptedLength(size_t srcLen)
            {
                return srcLen;
            }
            template<typename DestBuffType, typename SrcBuffType>
            void crypt(DestBuffType dest, const SrcBuffType src, size_t srcLen)
            {
                for(size_t i = 0; i < srcLen; ++i, ++keyindex)
                    dest[i] = src[i] ^ key[keyindex %= keysize];
            }
        private:
            KeyBuffType key;
            size_t keysize;
            size_t keyindex;
        };
    }
}

#endif
